package cn.newhopedairy.zmd.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @author Neo.Li
 * @date 2020-11-0518:52
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(WebSecurity web) {
        // WebSecurity绕过了Security的filter，适合于配置静态资源、不需要权限验证的三方回调等
        web
                .ignoring()
                .antMatchers("/static/**")
                .antMatchers("/vendors/**")
                .antMatchers("/webjars/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                // 激活oauth2鉴权登录功能
                .oauth2Login()
                .defaultSuccessUrl("/info");
    }

}
